package plus.stmt;

import plus.DynamicExtent;
import plus.Gripe;
import plus.VScope;
import plus.exp.Exp;
import plus.run.Emit;
import plus.run.VM;

public class P_Answer extends Statement {

	Exp e;

	public P_Answer(Exp e) {
		this.e = e;
	}

	@Override
	public void threadScope() {
		Gripe.context = this;
		DynamicExtent dynex = VScope.current.dynex;
		if (null == dynex.range) Gripe.gripe("Can't set return value from here.");
		e.threadScope();
		Gripe.context = this;
		dynex.range = e.unify_with(dynex.range);
		// Kind of odd that it makes DynamicExtent have a range Type. But seen as the
		// static definition of an activation record, it fits in a way.
	}

	@Override
	public void compile() {
		e.compilePush();
		Emit.asm(VM.PUSHBP);
		Emit.writeStack(DynamicExtent.cur.pParam);
	}
}
